<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="12" :offset="0">
        <el-card shadow="always" :body-style="{ padding: '20px' }">
          <template #header>
            <div>
              <span>柱状图-家具分类信息</span>
            </div>
          </template>
          <div class="chart" id="bar">
            <!-- 柱状图 -->
          </div>
        </el-card>
      </el-col>
      <el-col :span="12" :offset="0">
        <el-card shadow="always" :body-style="{ padding: '20px' }">
          <template #header>
            <div>
              <span>饼状图-商品购买情况统计</span>
            </div>
          </template>
          <div class="chart" id="pie"></div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import * as echarts from 'echarts';
import {onMounted} from 'vue'
import bar from './options/bar.js'
import pie from './options/pie.js'
//只有onMounted执行后，才能拿到真实DOM
onMounted(()=>{
  // 基于准备好的dom，初始化echarts实例
  var myChart = echarts.init(document.getElementById('bar'));
  // 绘制图表
  myChart.setOption(bar);

  //饼状图
  var pieChart = echarts.init(document.getElementById('pie'));
  pieChart.setOption(pie);
})
</script>

<style lang="scss" scoped>
.chart{
  height:240px;
  border:1px solid red;
}
</style>